from math import sqrt
a=int(input("Введите четырехзначное число: "))
b=a//1000

c=a//100%10

d=a//10%10

e=a%10

bc=a//100

bcd=a//10

cd=a//10%100

cde=a%1000

de=a%100

B=[a, b, bc, bcd, c, cd, cde, d, de,e] 
C=[]
for i in B:
       prime = True
       m = 2
       while m <= sqrt(i):
           if i % m == 0:
               prime = False
               break
           m += 1  
       if prime:
           C.append(i)
if len(C)>0:
       print (max(C))
else: print ('0')
